package com.mf.service.impl.basic;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.entity.dto.basic.DtoUser;
import com.mf.entity.req.basic.reqPublic.ReqRelevanceDetailById;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import com.mf.entity.dto.basic.DtoRolePermission;
import com.mf.entity.req.basic.search.SearchReqRolePermission;
import com.mf.mapper.basic.MapperRolePermission;
import com.mf.service.basic.ServiceRolePermission;
import org.springframework.transaction.annotation.Transactional;


@Service
public class ImplServiceRolePermission extends ServiceImpl<MapperRolePermission, DtoRolePermission> implements ServiceRolePermission {

    @Resource
    private MapperRolePermission mapperRolePermission;

    /**
     * 参数查询条件
     */
    @Override
    public LambdaQueryWrapper<DtoRolePermission> fillParams(SearchReqRolePermission params) {
        return null;
    }

    /**
     * 根据权限id查询绑定数量
     */
    @Override
    public long countByPermissionId(Integer permissionId) {
        final LambdaQueryWrapper<DtoRolePermission> wrapper = loadQw();
        wrapper.eq(DtoRolePermission::getPermissionId, permissionId);
        return count(wrapper);
    }

    /**
     * 根据角色id绑定权限
     */
    @Override
    @Transactional
    public void savePremByRoleId(ReqRelevanceDetailById reqRelevanceDetailById) {
        mapperRolePermission.delPremByRoleId(reqRelevanceDetailById);
        mapperRolePermission.savePremByRoleId(reqRelevanceDetailById,StpUtil.getSession().getModel(SaSession.USER, DtoUser.class).getId());
    }

    /**
     * 根据角色id删除绑定权限
     */
    @Override
    public void delPremByRoleId(ReqRelevanceDetailById reqRelevanceDetailById) {
        mapperRolePermission.delPremByRoleId(reqRelevanceDetailById);
    }


}